<?php
session_start();
//ini_set('display_errors',1);
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/database.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/functions.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.admin.php');
require($_SERVER['DOCUMENT_ROOT'].'/resources/lib/class.modules.php');
$admin=new admin();
$admin->canView($_SERVER['PHP_SELF']);


$file=$_FILES['logo']['tmp_name'];
$sizes=@getimagesize($file);

$width=$sizes[0];
$height=$sizes[1];
if($width<=5 && $height<=5) {
	die("I dont think so - try uploading at least a 6x6 image doofuss");	
}
$admin=new admin();
$filename=$_FILES['logo']['name'];
$ext=end(explode(".",$filename));
$move_to=$_SERVER['DOCUMENT_ROOT'].'/images/logo.'.$ext;
move_uploaded_file($file,$move_to);
$data=new database();
$data->db(DATABASE)->collection('settings');
$data->criteria(array('$set'=>array('logo'=>array('name'=>'logo.'.$ext,'width'=>intval($width),'height'=>intval($height)))));
$data->update((string)$admin->site_settings['_id']);
header("Location: /admin/");
?>